Skip to content

Fix df output on Windows#12244

Open
lhecker wants to merge 1 commit into
uutils:mainfrom
microsoft:windows/df
Open

Fix df output on Windows#12244
lhecker wants to merge 1 commit into
uutils:mainfrom
microsoft:windows/df

Conversation

@lhecker
Copy link
Copy Markdown

@lhecker lhecker commented May 11, 2026

This properly implements FsUsage using NT APIs. The choice
of GUID volume IDs is intentional as this matches PowerShell.

To assist with this, the PR introduces a new nt module,
which contains various helpers to interface with the NT API.
I expect their number to increase in the future, as the NT API
is rather well documented nowadays and expected to be stable.
They permit various implementations to be technically perfect,
such as the use of FILE_STAT_LX_INFORMATION.

Before:

Filesystem              Type  Size  Used Avail Use% Mounted on
\Device\HarddiskVolume3 NTFS  1.4T  749G     0 100%
\Device\HarddiskVolume4       730M  676M     0 100%
\Device\HarddiskVolume1       500M  168M     0 100%

After:

Filesystem                                        Type   Size  Used Avail Use% Mounted on
\\?\Volume{e7964102-1eaf-468b-a4df-dc8b143304b9}\ NTFS   1.4T  749G  625G  55% C:\
\\?\Volume{ac0578dc-5e8c-4f51-86e7-91bee5184973}\ NTFS   730M  676M   55M  93%
\\?\Volume{cc1ca74e-803a-4308-872c-d38f1157b9b2}\ FAT32  500M  168M  332M  34%

@DHowett
Copy link
Copy Markdown

DHowett commented May 11, 2026

If I’m honest, I have a minor preference for the short device node path rather than the volume GUID path; however, the volume guid is immediately accessible in an object browser, so… eh

@sylvestre
Copy link
Copy Markdown
Contributor

it will need new tests


use windows_sys::Win32::Foundation::NTSTATUS;

pub const SYNCHRONIZE: u32 = 0x00100000;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a lot of hardcoded values here
isn't that available in windows sys ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize we exported NT symbols via windows_sys::Wdk. I based lots of this on my own C++ snippets. I'll make the necessary changes.

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/printf/printf-surprise is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!
Note: The gnu test tests/misc/write-errors was skipped on 'main' but is now failing.

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented May 12, 2026

Does this break MSYS2 compatibility if people prefer native df binary?

@lhecker
Copy link
Copy Markdown
Author

lhecker commented May 13, 2026

I'm not sure what you - could you explain in more detail?
My understanding was that MSYS2 is its own thing, in particular because it uses POSIX paths. In this case, however, they also treat the Filesystem column fundamentally differently.

@lhecker
Copy link
Copy Markdown
Author

lhecker commented May 13, 2026

BTW I apologize, but I'll need some more time to get back to this PR. I'm currently ironing out some other kinks at Microsoft. (1-2 weeks.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants